import { GuideTipsManager } from "../../../manager/GuideTipsManager";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Cache } from "../../../cache/Cache";
import { AcupointCountdown } from "./AcupointCountdown";
import { GModuleEvent } from "../../../mvc/GModuleEvent";
import { LookupPlayerData } from "../LookupPlayerData";
import { AcupointData } from "./AcupointData";
import { AcupointConfig } from "../../../resource/AcupointConfig";
import { EffectManager } from "../../../manager/EffectManager";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { AcupointBuyNimbusPropWindow } from "./AcupointBuyNimbusPropWindow";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { TAcupointConfig } from "../../../../../Message/Db/Tables/TAcupointConfig";
type int = number;
//class AcupointIntroPanel
    
    export  class AcupointIntroPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._addNow = [];
            this._addNext = [];
            this.init();
            return;
        }

        public guideLevelUp(): void
        {
            var loc1=GuideTipsManager.getGuideTips(GuideTipsManager.Dir_TL, Language.getString(21001));
            loc1.x = this._upgradeButton.x + this._upgradeButton.width / 2;
            loc1.y = this._upgradeButton.y + this._upgradeButton.height;
            addChild(loc1);
            return;
        }

        public hideGuideLevelUp(): void
        {
            if (GuideTipsManager.guideTips.parent == this) 
            {
                GuideTipsManager.hideGuideTips();
            }
            GuideTipsManager.hideGuideTips2();
            return;
        }

        public dispose(): void
        {
            this.hideGuideLevelUp();
            return;
        }

        public set mode(arg1: string)
        {
            this._mode = arg1;
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ObjCreate.createBg(0, 0, 172, 147, this);
            var loc2=ObjCreate.createBg(0, 150, 172, 100, this);
            var loc3=ObjCreate.createBg(10, 47, 152, 2, this, ImagesConst.SplitLine);
            this._acupointTf = new GTextFormat(FontUtil.songtiName, 18, 16776960);
            this._effectTf = new GTextFormat("", 14, 16750848);
            this._conditionTf = new GTextFormat("", 12, 65280, null, null, null, null, null, null, null, null, null, 2);
            this._acupointTxt = this.createTextfield(10, 5, 150, 20, "", this._acupointTf);
            this._effectTxt = this.createTextfield(10, 25, 160, 45, "", this._effectTf);
            this._nextEffectTxt = this.createTextfield(10, 50, 160, 20, "", this._conditionTf);
            this._conditionTxt = this.createTextfield(10, 65, 160, 70, "", this._conditionTf);
            this._conditionTxt.defaultTextFormat = this._conditionTf;
            this._nimbusTxt = ObjCreate.createGTextField("", 10, 122, 100, 20, this, GlobalStyle.textFormat8);
            this._upgradeButton = ObjCreate.createGButton(Language.getString(30093), 100, 120, 65, 20, this, "Button");
            this._upgradeButton.addEventListener(flash.events.MouseEvent.CLICK, this.onUpgradeBtnClickHandler);
            this._coinNum = Cache.instance.role.money.coin + Cache.instance.role.money.coinBind;
            this._nimbusNum = Cache.instance.role.roleInfo.nimbus;
            this._countdownPanel = new AcupointCountdown();
            this._countdownPanel.x = 0;
            this._countdownPanel.y = 158;
            this.addChild(this._countdownPanel);
            return;
        }

        /* internal  */createTextfield(arg1: int, arg2: int, arg3: int, arg4: int, arg5: string, arg6: Object /* flash.text.TextFormat */): Object /* flash.text.TextField */
        {
            var loc1;
            (loc1 = new Object /* flash.text.TextField */()).selectable = false;
            loc1.mouseEnabled = false;
            loc1.x = arg1;
            loc1.y = arg2;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.text = arg5;
            loc1.setTextFormat(arg6);
            addChild(loc1);
            return loc1;
        }

        public updateIntroInfo(arg1: int, arg2: int, arg3: Boolean=false): void
        {
            var loc1=null;
            if (this._mode != GModuleEvent.Mode_Self) 
            {
                if (this._mode == GModuleEvent.Mode_Other) 
                {
                    loc1 = LookupPlayerData.acupointInfo;
                }
            }
            else 
            {
                loc1 = AcupointData.acupointInfo;
                this._nimbusTxt.text = Language.getString(30092) + "：" + Cache.instance.role.roleInfo.nimbus;
            }
            if (arg3) 
            {
                this._currentStep = arg2;
            }
            this._selectStep = arg2;
            this._selectLevel = AcupointData.getAcupointCurLevel(arg2, loc1);
            this._acupointInfo = AcupointConfig.instance.getAcupointInfo(this._selectLevel, arg2);
            var loc2=AcupointData.getAcupointName(arg2);
            this._acupointTxt.text = loc2 + " LV." + this._selectLevel;
            this._acupointTxt.setTextFormat(this._acupointTf);
            if (this._selectLevel >= AcupointData.topLevel) 
            {
                this._upgradeButton.visible = false;
                this._nextEffectTxt.htmlText = "";
            }
            this.updateAttributes(arg2);
            this.updateCondition(arg2, this._selectLevel);
            if (this._mode == GModuleEvent.Mode_Other) 
            {
                this._upgradeButton.enabled = false;
            }
            return;
        }

        /* internal  */updateCondition(arg1: int, arg2: int): void
        {
            var loc1=0;
            if (this._mode != GModuleEvent.Mode_Self) 
            {
                loc1 = AcupointData.getAcupointCurLevel(arg1, LookupPlayerData.acupointInfo);
            }
            else 
            {
                loc1 = AcupointData.getAcupointCurLevel(arg1, AcupointData.acupointInfo);
            }
            if (loc1 >= AcupointData.topLevel) 
            {
                this._conditionTxt.htmlText = "<p align=\'center\'><font size=\'14\' color=\'#00ff00\'>" + Language.getString(30094) + "</font></p>";
                return;
            }
            if (this._acupointInfo == null) 
            {
                return;
            }
            this._coinNum = Cache.instance.role.money.coin + Cache.instance.role.money.coinBind;
            this._nimbusNum = Cache.instance.role.roleInfo.nimbus;
            var loc2="<font size=\'12\' color=\'#00ff00\'>";
            var loc3=this._acupointInfo.cost;
            var loc4=this._acupointInfo.nimbus;
            var loc5="";
            if (Cache.instance.role.isOldPlayer) 
            {
                loc5 = Language.getString(27762);
            }
            var loc6="";
            loc6 = AcupointData.getNeedAcupoint(arg1, arg2);
            var loc7=true;
            if (this._coinNum < loc3 && this._mode == GModuleEvent.Mode_Self) 
            {
                loc2 = loc2 + Language.getString(30095) + "： <font color=\'#ff0000\'>" + loc3 + "</font>\n";
            }
            else 
            {
                loc2 = loc2 + Language.getString(30095) + "： " + loc3 + "\n";
            }
            if (this._nimbusNum < loc4 && this._mode == GModuleEvent.Mode_Self) 
            {
                loc2 = loc2 + Language.getString(30096) + "： <font color=\'#ff0000\'>" + loc4 + "</font>" + "  " + loc5 + "\n";
            }
            else 
            {
                loc2 = loc2 + Language.getString(30096) + "： " + loc4 + "  " + loc5 + "\n";
            }
            if (arg1 == this._currentStep) 
            {
                loc2 = loc2 + Language.getString(30097) + "： " + loc6 + "\n";
            }
            else 
            {
                loc7 = false;
                loc2 = loc2 + Language.getString(30097) + "： <font color=\'#ff0000\'>" + loc6 + "</font>\n";
            }
            loc2 = loc2 + "</font>";
            if (this._conditionTxt == null || this._upgradeButton == null) 
            {
                return;
            }
            this._conditionTxt.htmlText = loc2;
            this._upgradeButton.visible = true;
            if (loc7 && arg1 == this._currentStep && arg2 < 100 && this._mode == GModuleEvent.Mode_Self) 
            {
                this._upgradeButton.enabled = true;
                EffectManager.glowFilterReg(this._upgradeButton, [FilterConst.hintIconFilter], 0.3, 6, 3, 0);
            }
            else 
            {
                this._upgradeButton.enabled = false;
                EffectManager.glowFilterUnReg(this._upgradeButton);
            }
            return;
        }

        /* internal  */updateAttributes(arg1: int): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            var loc6=null;
            if (this._mode != GModuleEvent.Mode_Self) 
            {
                if (this._mode == GModuleEvent.Mode_Other) 
                {
                    loc1 = LookupPlayerData.acupointInfo;
                    loc2 = LookupPlayerData.lookupData.miniPlayer.career;
                    loc3 = LookupPlayerData.lookupData.miniPlayer.careerEnable;
                }
            }
            else 
            {
                loc1 = AcupointData.acupointInfo;
                loc2 = Cache.instance.role.careerBasic;
                loc3 = Cache.instance.role.careerEnabled;
            }
            var loc4=AcupointData.getAcupointCurLevel(arg1, loc1);
            this._addNow = AcupointData.getAttributesByStep(arg1, 1, loc1.attributes);
            this._addNext = AcupointData.getAttributesByStep(arg1, 2, loc1.attributes);
            var loc5=AcupointData.getAttributeStr(this._addNow, Language.getString(30098) + "：", loc2, loc3, true, false);
            this._effectTxt.text = loc5;
            this._effectTxt.setTextFormat(this._effectTf);
            if (loc4 < AcupointData.topLevel) 
            {
                loc6 = AcupointData.getAttributeStr(this._addNext, Language.getString(30090) + " ", loc2, loc3, true, false);
                this._nextEffectTxt.text = loc6;
                this._nextEffectTxt.setTextFormat(this._conditionTf);
                this._nextEffectTxt.y = this._effectTxt.textHeight + 33;
                this._conditionTxt.y = this._effectTxt.textHeight + this._nextEffectTxt.textHeight + 32;
            }
            return;
        }

        /* internal  */onUpgradeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            var loc2=0;
            if (this._acupointInfo && Cache.instance.role.isOldPlayer) 
            {
                loc1 = this._acupointInfo.nimbus / 2;
            }
            else if (this._acupointInfo) 
            {
                loc1 = this._acupointInfo.nimbus;
            }
            if (this._acupointInfo && this._coinNum < this._acupointInfo.cost) 
            {
                loc2 = this._acupointInfo.cost - this._coinNum;
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallAutoBuyCoin, loc2));
            }
            else if (this._acupointInfo && this._nimbusNum < loc1) 
            {
                if (this._buyNimbusProp == null) 
                {
                    this._buyNimbusProp = new AcupointBuyNimbusPropWindow();
                }
                this._buyNimbusProp.show();
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AcupointBeginUpgrade));
            }
            this.hideGuideLevelUp();
            return;
        }

        public updateCountdownInfo(): void
        {
            if (AcupointData.leftTimes < 0) 
            {
                return;
            }
            EffectManager.glowFilterUnReg(this._upgradeButton);
            var loc1=AcupointData.curTotalTime;
            this._countdownPanel.updateSpeedUpInfo(loc1);
            return;
        }

        public removeCountdownInfo(): void
        {
            if (this._countdownPanel && this._countdownPanel.parent) 
            {
                this._countdownPanel.stopTimer();
                removeChild(this._countdownPanel);
            }
            return;
        }

        public updateNimbus(arg1: int): void
        {
            this._nimbusTxt.htmlText = Language.getString(30092) + "：" + arg1;
            this._nimbusNum = arg1;
            if (AcupointData.leftTimes > 0 || this._selectStep <= 0) 
            {
                return;
            }
            this.updateCondition(this._selectStep, this._selectLevel);
            return;
        }

        public updateMoney(): void
        {
            this._coinNum = Cache.instance.role.money.coin + Cache.instance.role.money.coinBind;
            if (AcupointData.leftTimes > 0 || this._selectStep <= 0) 
            {
                return;
            }
            this.updateCondition(this._selectStep, this._selectLevel);
            return;
        }

        /* internal */ /* var */_acupointTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_effectTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_nextEffectTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_conditionTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_acupointTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_effectTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_conditionTf: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_upgradeButton: GButton;

        /* internal */ /* var */_currentStep: int;

        /* internal */ /* var */_acupointInfo: TAcupointConfig;

        /* internal */ /* var */_addNow: Array<any>;

        /* internal */ /* var */_addNext: Array<any>;

        /* internal */ /* var */_countdownPanel: AcupointCountdown;

        /* internal */ /* var */_coinNum: int;

        /* internal */ /* var */_nimbusNum: int;

        /* internal */ /* var */_selectStep: int;

        /* internal */ /* var */_nimbusTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_buyNimbusProp: AcupointBuyNimbusPropWindow;

        /* internal */ /* var */_mode: string="自己";

        /* internal */ /* var */_selectLevel: int;
    }
